package com.simpletour.qa.service.controller;


import com.simpletour.qa.common.http.ObjectRestResponse;
import com.simpletour.qa.common.http.ResponseCode;
import com.simpletour.qa.common.http.ResponseMsg;
import com.simpletour.qa.service.entity.Question;
import com.simpletour.qa.service.entity.QuestionLike;
import com.simpletour.qa.service.entity.QuestionLikeCount;
import com.simpletour.qa.service.service.QuestionLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/questionlike")
public class QuestionLikeController {


    @Autowired
    private QuestionLikeService questionLikeService;


    @PostMapping("")
    public ObjectRestResponse<Question> update(@RequestBody @Valid QuestionLike questionLike,BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            List<FieldError> errorList = bindingResult.getFieldErrors();
            return ObjectRestResponse.builder().code(ResponseCode.PARAM_CHECK_ERROR).build();
        }
        QuestionLikeCount questionLikeCount = questionLikeService.update(questionLike);
        return ObjectRestResponse.builder().code(ResponseCode.SUCCESS).msg(ResponseMsg.SUCCESS).result(questionLikeCount).build();

    }

   /* @DeleteMapping("")
    public ObjectRestResponse<Question> delete(int userId,int questionId){
        QuestionLikeCount questionLikeCount= questionLikeService.deleteByUserIdAndQuestionId(userId, questionId);
        return ObjectRestResponse.builder().code(ResponseCode.SUCCESS).msg(ResponseMsg.SUCCESS).result(questionLikeCount);
    }*/

}
